<?php
// TODO: Unauthorized access before 404 not found
return array(
    'service_manager' => array(
        'factories' => array(
            'Ticket\Repository\CategoryRepository' => function($sm) {
                $config = $sm->get('Config');
                $categories = isset($config['ticket_categories']) ? $config['ticket_categories'] : array();
                $repository = new \Ticket\Repository\InMemoryCategoryRepository($categories);
                return $repository;
            },
            'Ticket\Repository\TicketRepository' => function($sm) {
                $entityManager = $sm->get('Doctrine\ORM\EntityManager');
                $repository = $entityManager->getRepository('Ticket\Entity\Ticket');
                return $repository;
            },
            'Ticket\Form\TicketForm' => 'Ticket\Form\TicketFormFactory',
            'Ticket\Form\TicketUpdateForm' => 'Ticket\Form\TicketUpdateFormFactory',
            'Ticket\Widget\MyTickets' => function($sm) {
                $mytickets = new Ticket\Widget\MyTickets();
                $mytickets->setAutenticationService($sm->get('Authentication\Service\AuthenticationService'));
                $mytickets->setTicketRepository($sm->get('Ticket\Repository\TicketRepository'));
                $mytickets->setRouter($sm->get('Router'));

                return $mytickets;
            }
        ),
    ),
    'doctrine' => array(
        'driver' => array(
            'ticket_entities' => array(
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/Ticket/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                    'Ticket\Entity' => 'ticket_entities'
                )
            )
        )
    ),
    'controllers' => array(
        'invokables' => array(
            'Ticket\Controller\Ticket' => 'Ticket\Controller\TicketController',
            'Ticket\Controller\ReportController' => 'Ticket\Controller\ReportController',
        ),
    ),
    'roles' => array(
        'helpdesk' => null,
        'technician' => null,
        'admin' => array('helpdesk'), // TODO: REVERT TO NULL! THIS IS FOR DEBUG ONLY!
    ),
    'authorization' => array(
        'Ticket\Controller\Ticket' => array(
            'index' => 'helpdesk',
            'view' => 'helpdesk',
            'add' => 'helpdesk',
            'edit' => 'helpdesk',
            'close' => 'helpdesk',
            'delete' => 'helpdesk',
        ),
        'Ticket\Controller\ReportController' => array(
            'find' => 'helpdesk',
            'history' => 'helpdesk',
            'newTicket' => 'helpdesk',
        ),
    ),
    'router' => array(
        'routes' => array(
            'reportticket' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/reportticket[/:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Ticket\Controller\ReportController',
                        'action' => 'find',
                    ),
                ),
            ),
            'ticket' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/ticket[/:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Ticket\Controller\Ticket',
                        'action' => 'index',
                    ),
                ),
            ),
        ),
    ),
    'navigation' => array(
        'default' => array(
            array(
                'label' => 'Ticket',
                'route' => 'ticket',
                'resource' => 'Ticket\Controller\Ticket',
                'privilege' => 'index',
            ),
        )
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'ticket' => __DIR__ . '/../view',
        ),
    ),
    'ticket_categories' => array(
        'profil',
        'sprzęt',
        'hasło',
    ),
                
    'widgets' => array(
        'Ticket\Widget\MyTickets',
    ),               
);